﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ants
{
    static class AntHelper
    {
        public static List<Location> Moves = new List<Location>();



        public static bool IsValidPath(IGameState state, Location loc1, Location loc2)
        {

            Direction firstDirection = GetFirstDirection(state, loc1, loc2);

            if (IsValidTile(state, state.GetDestination(loc1, firstDirection)))
            {
                return true;
            }
            return false;
        }

        public static Direction GetFirstDirection(IGameState state, Location loc1, Location loc2)
        {

            if (loc1.Row < loc2.Row)
            {
                if ((loc2.Row - loc1.Row >= state.Height / 2))
                {
                    return Direction.North;
                }
                if ((loc2.Row - loc1.Row <= state.Height / 2))
                {
                    return Direction.South;
                }
            }
            if (loc2.Row < loc1.Row)
            {
                if ((loc1.Row - loc2.Row >= state.Height / 2))
                {
                    return Direction.South;
                }
                if ((loc1.Row - loc2.Row <= state.Height / 2))
                {
                    return Direction.North;
                }
            }
            if (loc1.Col < loc2.Col)
            {
                if ((loc2.Col - loc1.Col >= state.Width / 2))
                {
                    return Direction.West;
                }
                if ((loc2.Col - loc1.Col <= state.Width / 2))
                {
                    return Direction.East;
                }
            }
            if (loc2.Col < loc1.Col)
            {
                if ((loc1.Col - loc2.Col >= state.Width / 2))
                {
                    return Direction.East;
                }
                if ((loc1.Col - loc2.Col <= state.Width / 2))
                {
                    return Direction.West;
                }
            }
            return Direction.Pass;
        }

        public static bool IsValidTile(IGameState state, Location loc1)
        {
            if ( (state.GetIsUnoccupied(loc1)) && (!Moves.Contains(loc1)) )
            {
                return true;
            }
            return false;
        }
    }
}
